With the 'clicked' attribute you can set a script file that is called when the block changes it's state from powered to unpowered/idle. You can use world and origin for your script.
deactivated="loader.loadScript('xyz.script');";